package com.study.doc.controller;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.study.doc.search.DoSearch;
import com.study.doc.search.Result;
import org.ansj.domain.Term;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class SearchController {

    private static DoSearch doSearch = new DoSearch();

    private static ObjectMapper objectMapper = new ObjectMapper();

    @GetMapping(value = "/searcher",produces = "application/json;charset=utf-8")
    @ResponseBody
    public String search(@RequestParam("query") String query) throws JsonProcessingException {
        List<Result> results = doSearch.Search(query);
        return objectMapper.writeValueAsString(results);
    }
}
